<template>
  <basic-container class="personal">
    <avue-crud
      :option="grid1"
      :table-loading="loading"
      :data="data"
      v-model="form"
      :page.sync="page"
      :header-cell-class-name="headerClass"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-edit-outline"
          size="small"
          @click.stop="userprojectgaugesubjectanswer(scope.row)"
          >查看题目
        </el-button>
        <el-button
          type="text"
          icon="el-icon-edit-outline"
          size="small"
          @click.stop="getToReport(scope.row)"
          >生成报告
        </el-button>
      </template>
    </avue-crud>
    <el-dialog
      title="已考题目列表"
      :visible.sync="answerDetailDialogView"
      class="dialogInfoCss"
    >
      <div class="container">
        <answerDetailDialog :answerData="answerData"></answerDetailDialog>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
import {
  getUserprojectgauge,
  getUserprojectgaugesubjectanswer,
} from "@/api/evaluation/personal";
import answerDetailDialog from "./answerDetailDialog";
export default {
  components: { answerDetailDialog },
  data() {
    return {
      form: {},
      answerData: [],
      answerDetailDialogView: false,
      selectionList: [],
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      grid1: {
        height: 450,
        calcHeight: 210,
        tip: false,
        searchShow: true,
        searchMenuSpan: 4,
        viewBtn: false,
        card: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        border: true,
        index: true,
        selection: false,
        dialogClickModal: false,
        // refreshBtn: false,
        // searchShowBtn: false,
        // columnBtn: false,
        menuSpan: 3,
        align: "left",
        column: [
          {
            label: "项目名",
            search: true,
            searchSpan: 5,
            prop: "projectName",
          },
          {
            label: "学号",
            prop: "code",
            searchSpan: 5,
          },
          {
            label: "姓名",
            prop: "userName",
            search: true,
            searchSpan: 5,
          },
          {
            label: "年级",
            type: "select",
            prop: "gradeName",
            search: true,
            searchSpan: 5,
            props: {
              label: "gradeName",
              value: "gradeName",
            },
            dicUrl: `/api/blade-system/grade/list`,
          },
          {
            label: "班级",
            prop: "className",
            search: true,
            searchSpan: 5,
          },
          {
            label: "性别",
            prop: "sex",
            type: "select",
            dataType: "number",
            dicData: [
              {
                label: "男",
                value: 1,
              },
              {
                label: "女",
                value: 2,
              },
              {
                label: " ",
                value: -1,
              },
            ],
          },
          {
            label: "测验结束时间",
            prop: "endTime",
          },
        ],
      },
      data: [],
    };
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    userprojectgaugesubjectanswer(row) {
      this.answerData = [];
      getUserprojectgaugesubjectanswer(1, 1000, {
        userProjectGaugeId: row.id,
      }).then((result) => {
        if (result.data.code == "200") {
          if (result.data.data.records.length) {
            this.answerData = result.data.data.records;
            this.answerDetailDialogView = true;
          } else {
            this.$message.warning("没有可以查看的题目！");
          }
        }
      });
    },
    onLoad(page, params = {}) {
      if (window.localStorage.getItem("saber-userInfo")) {
        params.tenantId = JSON.parse(
          window.localStorage.getItem("saber-userInfo")
        ).content.tenantId;
      }
      this.loading = true;
      if (this.$route.query.userId) params.includeId = this.$route.query.userId;
      getUserprojectgauge(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
      this.loading = false;
    },
    getToReport(row) {
      this.$router.push({
        name: "个人测评报告",
        query: {
          id: row.id,
          projectName: row.projectName,
        },
      });
    },
    headerClass() {
      return "text-align:left";
    },
  },
};
</script>

<style lang="scss" scoped>
.personal {
  .container {
    height: 70vh;
    overflow-y: auto;
  }
  .dialogInfoCss {
    overflow-y: hidden;
    margin-top: -50px;
    // margin-bottom: 40px;
  }
}
</style>
